<template>
  <div class="home">
    <!--导航-->
    <van-nav-bar fixed title="智慧商城" />
    <!--搜索框-->
    <div class="search">
      <van-search
        background="#f1f1f2"
        placeholder="请输入搜索关键词"
        readonly
        shape="round"
        @click="$router.push('/search')"
      />
    </div>
    <!--轮播图-->
    <van-swipe :autoplay="2000" class="my-swipe" indicator-color="white">
      <van-swipe-item v-for="item in bannerList" :key="item.imgUrl">
        <img :src="item.imgUrl" alt="" />
      </van-swipe-item>
    </van-swipe>
    <!--通知栏-->
    <van-notice-bar id="noticeList" :text="noticeList" left-icon="volume-o" />
    <!--宫格-->
    <van-grid :column-num="5" icon-size="40">
      <van-grid-item
        v-for="item in navList"
        :key="item.imgUrl"
        :icon="item.imgUrl"
        :text="item.text"
      />
    </van-grid>
    <!--主会场-->
    <div class="main">
      <img :src="venueList.imgUrl" alt="" />
    </div>
    <!--猜你喜欢-->
    <div class="guess">
      <div id="guessList">{{ guessList }}</div>
      <div class="goods-list">
        <GoodsItem
          v-for="item in proList"
          :key="item.goods_id"
          :item="item"
        ></GoodsItem>
      </div>
    </div>
  </div>
</template>
<script>
import GoodsItem from '@/components/GoodsItem.vue'
import { getHomeData } from '@/api/home'

export default {
  name: 'homeCom',
  components: { GoodsItem },
  data () {
    return {
      noticeList: '', // 通知栏
      guessList: [], // 猜你喜欢
      bannerList: [], // 轮播图
      navList: [], // 宫格
      proList: [], // 商品列表
      venueList: [] // 主会场
    }
  },
  computed: {},
  methods: {},
  async created () {
    const {
      data: {
        data: { pageData }
      }
    } = await getHomeData()
    this.bannerList = pageData.items[1].data
    this.noticeList = pageData.items[2].params.text
    this.navList = pageData.items[3].data
    this.venueList = pageData.items[4].data[0]
    this.guessList = pageData.items[5].params.content
    document.getElementById('guessList').innerHTML = this.guessList
    this.proList = pageData.items[6].data
  }
}
</script>
<style lang="less" scoped>
.home {
  padding-top: 45px;
  padding-bottom: 50px;

  .van-nav-bar {
    z-index: 999;
    background-color: #c21401;

    ::v-deep .van-nav-bar__title {
      color: #fff;
    }
  }

  .van-search {
    width: 100%;
    z-index: 999;
  }

  .my-swipe .van-swipe-item {
    color: #fff;
    text-align: center;

    img {
      width: 100%;
      height: 185px;
    }
  }

  .van-notice-bar {
    margin-top: -5px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 17px;
  }

  .main {
    img {
      background-repeat: no-repeat;
      width: 100%;
    }
  }

  .guess {
    margin-top: 5px;

    p {
      text-align: center;
      font-size: 20px;
      padding-bottom: 10px;
      border-bottom: 1px solid #dfe1e5;
    }

    .goods-list {
      background-color: #f6f6f6;
    }
  }
}
</style>
